package org.sipsl.gisystems.gentest.rte.commands;

import java.io.BufferedWriter;
import java.io.FileWriter;

import org.sipsl.gisystems.gentest.rte.util.DataParams;
import org.sipsl.gisystems.gentest.rte.util.GenericUtil;
import org.sipsl.gisystems.gentest.rte.util.Params;


public class ExpectedCounter extends RteCommand {

	private int counter;
	private long remain;
	private String counterIdValue;
	
	public ExpectedCounter(long _remain, int _counter, Params p) {
		super(p);
		counter = _counter;
		remain = _remain;
		
		counterIdValue = "";
	    if (p.getGeneric("COUNTERIDCHECKVALUE")!=null){
	    	if (counter < 7){
	    		counterIdValue = ":CID"+counter+","+p.getGeneric("COUNTERIDCHECKVALUE");
	    	}else if (counter >=7){
	    		counterIdValue = ":CID"+(counter-6)+","+p.getGeneric("COUNTERIDCHECKVALUE");
	    	}
	    		
	    }

		
		// TODO Auto-generated constructor stub
	}

	@Override
	public String getScript() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void  dumpScript(String title, int i){
		try  
		{
			String prefix = GenericUtil.MakePrefix(i);
			
		    FileWriter fstream = new FileWriter(title+"/"+prefix+":expectcounter-New.exp"); //true tells to append data.
		    BufferedWriter out = new BufferedWriter(fstream);


		    int CV = 0;
		    String SEQ ="";
		    //:SUBID,447300030203:SUBACC,0:CTTYPE,0:SPARE,ALL:SEQNO,2:CID1,D60:CV1,94371840:CV2,0:CV3,0:CV4,0:CV5,0;
			if (counter < 7){
		    	out.write(":SUBID,"+p.getMSISDN()+":SUBACC,0:CTTYPE,0:SPARE,ALL:SEQNO,1"+counterIdValue+":CV"+counter+","+remain+";\n");
		    	CV = counter;
		    	SEQ = " 1 ";
			}else if (counter >=7){
		    	out.write(":SUBID,"+p.getMSISDN()+":SUBACC,0:CTTYPE,0:SPARE,ALL:SEQNO,2"+counterIdValue+":CV"+(counter-6)+","+remain+";\n");
		    	CV = counter-6;
		    	SEQ = " 2 ";
			}
	    	
		    out.flush();
		    out.close();
		    
		    testDescription = "Expected counter " + CV + " sequence nr " + SEQ +
		    		" is " + remain;
		    if (counterIdValue.length()>0){
		    	testDescription = testDescription + " and CID is " + p.getGeneric("COUNTERIDCHECKVALUE");
		    }

		}
		catch (Exception e)
		{
		    System.err.println("Error: " + e.getMessage());
		}
		
	}

}
